import {useNavigation} from '@react-navigation/native';
import QRScanner from '../../QRScanner';
import {NativeStackNavigationProp} from '@react-navigation/native-stack';
import {RootStackParamList} from '../../Nav/routes';
import {useScannerProvider} from '../../../hooks/useScannerProvider';

export default function ScannerView() {
  const navigation =
    useNavigation<NativeStackNavigationProp<RootStackParamList>>();

  const {setCodeResult} = useScannerProvider();

  return (
    <QRScanner
      onScanResult={value => {
        console.log('Scan code result', value);
        if (value != null && value != undefined) {
          setCodeResult({
            codeResult: value!,
            timestamp: new Date().getTime(),
          });

          navigation.pop();
        }
      }}></QRScanner>
  );
}
